
<!DOCTYPE html >
<html>
<head>
    <meta name="Generator" content="ECSHOP v2.7.3" />
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <title>购物车  </title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <meta name="Keywords" content="" />
    <meta name="Description" content="" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet"  href="/template/default/css/public.css">
    <link rel="stylesheet"  href="/template/default/css/flow.css">
    <link rel="stylesheet" type="text/css" href="http://nsr.9hive.cn/global/vendor/layer/mobile/need/layer.css"/>

    <script type="text/javascript" src="https://static.9hive.cn/global/vendor/jquery/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/template/default/js/ecsmart.js"></script>
    <script type="text/javascript" src="/template/default/js/jquery.json.js"></script>
    <script type="text/javascript" src="/template/default/js/transport.js"></script>
    <script type="text/javascript" src="/template/default/js/common.js"></script>
    <script type="text/javascript" src="/template/default/js/utils.js"></script>
    <script type="text/javascript" src="/template/default/js/shopping_flow.js"></script>
    <script type="text/javascript" src="http://nsr.9hive.cn/global/vendor/layer/mobile/layer.js"></script>


    <script type="text/javascript" src="/res/js/jquery.metadata.js"></script>
    <!--<script type="text/javascript" src="https://static.9hive.cn/global/vendor/layer/layer.js"></script>-->
</head>
<body style="background: rgb(235, 236, 237);">
<div class="tab_nav">
    <div class="header">
        <div class="h-left">
            <a class="sb-back" href="javascript:history.back(-1)" title="返回"><img src="/template/default/images/arrow_left_white.png"/></a>
        </div>
        <div class="h-mid">
            购物车      </div>
    </div>
</div>

<div class="screen-wrap fullscreen login">
    <%if (cartItemList! == null || cartItemList.~size == 0){%>
        <section id="cart-content">
            <div class="qb_tac" style="padding:50px 0">
                <img src="/template/default/images/empty_cart.png" width="100" height="95">
                <br>购物车还是空的</div>
            <div class="qb_gap" style="width:60%; margin:0 auto;">
                <a href="/wap.html" class="mod_btn btn_strong" >马上逛逛</a>
            </div>
        </section>
    <%}else{%>
    <div class="page-shopping" >
        <div>
            <form id="formCart" name="formCart" method="post" action="flow.php">
                <%for(list in cartItemList!){%>
                <%var product=list.product;%>
                    <div class="item-list">
                        <div class="item">
                            <div class="inner">
                                <div style="width:60%; float:left; height:98px;">
                                    <div class="check-wrapper">
                                        <!--<span  class="cart-checkbox checked" >--><!--选择按钮,待改进-->
                                        <input type="checkbox" autocomplete="off" name="sel_cartgoods[]" value="4121" id="sel_cartgoods_4121" checked=checked  style="display:none;"></span>
                                    </div>
                                    <div  class="pic">
                                        <a href="/b/product/detailWap?id=${product.id}&shopId=${shopId!}">
                                            <img src="${product.productImageList[0].sourceProductImagePath!}" ></a>
                                    </div>
                                    <div class="name">
                                        <span style="font-size: 12px"><%if(strutil.length(product.name)>9){print(strutil.subStringTo(product.name,0,9));}else{print(product.name);}%></span>
                                    </div>
                                    <div class="attr" style="height: auto">
                                        <span>${product.specificationValues}</span>
                                    </div>
                                    <div class="num">
                                        <div class="xm-input-number">
                                            <a href="javascript:;" onclick="reduceNum('${product.id}')" id="jiannum4121"  class="input-sub  "></a>
                                            <input type="text" id="quantity_${product.id}" value="${list.quantity}" class="input-num" onkeyup="this.value=this.value.replace(/\D/g,'')"  onchange="changeNum('${list.product.id}')"/>
                                            <a href="javascript:;" onclick="addNum('${product.id}')" class="input-add active"></a>
                                        </div>
                                    </div>
                                </div>
                                <div style=" position:absolute; right:0px; top:20px; width:100px; height:98px;">
                                    <div class="price">
                                        <span class="mar_price">￥${product.marketPrice}元</span>
                                        <br>
                                        <span>￥${product.price}元</span>
                                    </div>
                                    <div class="delete">
                                        <a href="javascript: void(0);" class="deleteCartItem {id: '${product.id}'}">
                                            <div class="icon-shanchu"></div>
                                        </a>
                                    </div>
                                </div>
                                <div style="height:0px; line-height:0px; clear:both;"></div>
                            </div>
                            <div class="append"></div>
                        </div>
                    </div>
                <%}%>
                <input type="hidden" name="step" value="update_cart">

                <div class="bottom-panel" >
                    <!--<div class="quanxuan">
                        <div class="check-wrapper">
                            <span  class="cart-checkbox checked" onclick="return chkAll_onclick()"></span><span class="cart-checktext">全选</span>
                        </div>
                    </div>-->
                    <div class="info">
                        <span class="hot" id="totalPrice"><em>总计：</em>￥${totalPrice!0}元</span>
                        <br>
                        <span class="hot_text">不含运费</span>
                    </div>
                    <div class="right">
                        <a href="/b/order/info?shopId=${shopId!}">
                            <input type="button"  class="xm-button " value="去结算">
                        </a>
                    </div>

                </div>
            </form>
        </div>
    </div>
    <%}%>

    <script type="text/javascript">
        //编辑购物车
        function changeNum(id){
            var $quantity = $("#quantity_"+id);
            var $totalPrice = $("#totalPrice");//商品总价
            var quantity=parseInt($quantity.val());
            $.ajax({
                url: "/b/cartItem/ajaxEdit",
                data: {"id": id, "quantity": quantity},
                dataType: "json",
                async: false,
                success: function(data) {
                    if (data.status == "success") {
                        $("#quantity_"+id).val(quantity);
                        $totalPrice.text(data.totalPrice);
                    } else {

                    }
                }
            });
        }

        //增加商品数量
        function addNum(id){
            var $quantity = $("#quantity_"+id);
            var $totalPrice = $("#totalPrice");//商品总价
            var quantity=parseInt($quantity.val())+1;
            $.ajax({
                url: "/b/cartItem/ajaxEdit",
                data: {"id": id, "quantity": quantity},
                dataType: "json",
                async: false,
                success: function(data) {
                    if (data.status == "success") {
                        $("#quantity_"+id).val(quantity);
                        $totalPrice.text(data.totalPrice);
                    } else {

                    }
                }
            });
        }

        //减少商品数量
        function reduceNum(id){
            var $quantity = $("#quantity_"+id);
            var $totalPrice = $("#totalPrice");//商品总价
            var quantity=parseInt($quantity.val())-1;
            var reg = /^[1-9]\d*$/;
            if(!reg.test(quantity)){
                return;
            }
            $.ajax({
                url: "/b/cartItem/ajaxEdit",
                data: {"id": id, "quantity": quantity},
                dataType: "json",
                async: false,
                success: function(data) {
                    if (data.status == "success") {
                        $("#quantity_"+id).val(quantity);
                        $totalPrice.text(data.totalPrice);
                    } else {

                    }
                }
            });
        }
        // 删除购物车项
        $(".deleteCartItem").click( function() {
            $this = $(this);
            var id = $this.metadata().id;
            var shopId = $this.metadata().shopId;


            layer.open({
                content: '您确定要删除吗？'
                , btn: ['是', '否']
                , yes: function (index) {
                    $.ajax({
                        url: "/b/cartItem/ajaxDelete",
                        data: {"id": id},
                        dataType: "json",
                        async: false,
                        success: function(data) {
                            if (data.status == "success") {
                                window.location.reload();
                            }
                        }
                    });

                    layer.close(index);
                }
            });


        });
    </script>

    <script type="text/javascript" charset="utf-8">

        $(".inner .cart-checkbox").click(function(){
            if($(this).hasClass('checked')){
                $(this).removeClass('checked');
                $(this).find('input').attr('checked',false);
            }
            else
            {
                $(this).addClass('checked');
                $(this).find('input').attr('checked',true);
            }


            if($(".inner .cart-checkbox")==true)
            {
                $('.quanxuan .cart-checkbox').addClass('checked');
            }
            else
            {
                $('.quanxuan .cart-checkbox').removeClass('checked');
            }

            var is_checked = true;
            $('.inner .cart-checkbox').each(function(){
                if(!$(this).hasClass('checked'))
                {
                    is_checked = false;
                    return false;
                }
            });
            if(is_checked){
                $('.quanxuan .cart-checkbox').addClass('checked');
            }else
            {
                $('.quanxuan .cart-checkbox').removeClass('checked');
            }
            select_cart_goods();

        });


        function chkAll_onclick()
        {
            var is_checked = false;
            if($('.quanxuan .cart-checkbox').hasClass('checked')){
                $('.quanxuan .cart-checkbox').removeClass('checked');
                $('.inner .cart-checkbox').removeClass('checked');
                is_checked = false;
            }
            else{
                $('.quanxuan .cart-checkbox').addClass('checked');
                $('.inner .cart-checkbox').addClass('checked');
                is_checked = true;
            }
            for (var i=0;i<document.formCart.elements.length;i++)
            {
                var e = document.formCart.elements[i];
                e.checked = is_checked;
            }
        }


    </script>

    <div style=" height:72px; clear:both"></div>

</div>


</body>
</html>